////////////////////////////////////////////////////////////////////////////////
// Filename: horizontalblur.ps
////////////////////////////////////////////////////////////////////////////////

Texture2D shaderTexture : register(t0);

SamplerState samLinear
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Wrap;
    AddressV = Wrap;
};

struct PixelInputType
{
    float4 position : SV_POSITION;
    float2 tex		: TEXCOORD0;
};


static const float	_W	= 1.0f/800.0f;
static const float	_H	= 1.0f/600.0f;

static const float2 HorTexelKernel[13] =
{
    { -6*_W, 0*_H },
    { -5*_W, 0*_H },
    { -4*_W, 0*_H },
    { -3*_W, 0*_H },
    { -2*_W, 0*_H },
    { -1*_W, 0*_H },
    {  0*_W, 0*_H },
    {  1*_W, 0*_H },
    {  2*_W, 0*_H },
    {  3*_W, 0*_H },
    {  4*_W, 0*_H },
    {  5*_W, 0*_H },
    {  6*_W, 0*_H },
};

static const float2 VerTexelKernel[13] =
{
    { 0*_W, -6*_H },
    { 0*_W, -5*_H },
    { 0*_W, -4*_H },
    { 0*_W, -3*_H },
    { 0*_W, -2*_H },
    { 0*_W, -1*_H },
    { 0*_W,  0*_H },
    { 0*_W,  1*_H },
    { 0*_W,  2*_H },
    { 0*_W,  3*_H },
    { 0*_W,  4*_H },
    { 0*_W,  5*_H },
    { 0*_W,  6*_H },
};


static const float BlurWeights[13] = 
{
    0.002216,
    0.008764,
    0.026995,
    0.064759,
    0.120985,
    0.176033,
    0.199471,
    0.176033,
    0.120985,
    0.064759,
    0.026995,
    0.008764,
    0.002216,
};

////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 HorizontalBlurPixelShader(PixelInputType input) : SV_TARGET
{
	float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f);
	[unroll] for (int i = 0; i < 13; i++)
	{    
		color += shaderTexture.Sample(samLinear, input.tex + HorTexelKernel[i].xy ) * BlurWeights[i];
	}

	return color;
}

float4 VerticalBlurPixelShader(PixelInputType input) : SV_TARGET
{
	float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f);
	[unroll] for (int i = 0; i < 13; i++)
	{    
		color += shaderTexture.Sample(samLinear, input.tex + VerTexelKernel[i].xy ) * BlurWeights[i];
	}

	return color;
}